use crate::http::client::{Error, rpc, watch};
use crate::http::route;
use std::sync::Arc;

pub struct NodeClient {
    rpc_client: Arc<rpc::Client>,
}

impl NodeClient {
    pub fn new(rpc_client: Arc<rpc::Client>) -> Self {
        Self { rpc_client }
    }

    pub async fn watch<T>(&self, node_id: &str, handler: T) -> Result<watch::WatchTask<T>, Error>
    where
        T: watch::TextMessageHandler + 'static,
    {
        let path = route::path_ws_nodes(node_id);
        self.rpc_client.watch(path.as_str(), handler).await
    }
}
